
package com.yuan.model;

import com.yuan.prefence.FileConstants;
import com.yuan.prefence.UrlConstants;
import com.yuan.unit.FileUtils;
import com.yuan.unit.HttpUtils;
import com.yuan.unit.JsonUtils;

import android.content.Context;

import java.util.ArrayList;
import java.util.Map;

/**
 * Config entity. @author MyEclipse Persistence Tools
 */

@SuppressWarnings("serial")
public class Config implements java.io.Serializable {

    private Integer id;
    private String run;
    private String companyname;
    private String sn;
    private String url;
    private String 夏冬;

    // Constructors

    /** default constructor */
    private Config() {
    }

    private static Config sInstance;

    public static Config getInstance() {
        if (sInstance == null) {
            synchronized (Config.class) {
                if (sInstance == null) {
                    sInstance = new Config();
                }
            }
        }
        return sInstance;
    }

    public void setFromMap(Map<?, ?> map) {
        try {
            this.id = (Integer) map.get("id");
            this.run = (String) map.get("run");
            this.companyname = (String) map.get("companyname");
            this.sn = (String) map.get("sn");
            this.url = (String) map.get("url");
            this.夏冬 = (String) map.get("夏冬");
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    // Property accessors

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRun() {
        return this.run;
    }

    public void setRun(String run) {
        this.run = run;
    }

    public String getCompanyname() {
        return this.companyname;
    }

    public void setCompanyname(String companyname) {
        this.companyname = companyname;
    }

    public String getSn() {
        return this.sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String get夏冬() {
        return this.夏冬;
    }

    public void set夏冬(String 夏冬) {
        this.夏冬 = 夏冬;
    }

    /**
     * 获取配置文件从网络 存在网络失败 IO异常 JSON转化错误 存在错误在返回false 全部正确fen
     * 
     * @param context
     * @return
     */
    public boolean getConfigFromNet(Context context)
    {
        String config = null;
        try {
            config = HttpUtils.getUrlContent(context, UrlConstants.CONFIGURL, "UTF-8");
            ArrayList<?> list = JsonUtils.getList(config);
            FileUtils.Serializable2File(list, FileConstants.SERIALIZABLE_CONFIG);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
}
